const path = require('path');
const htmlPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const VueLoaderPlugin = require('vue-loader/lib/plugin')

module.exports = {
    entry:'./src/js/index.js',
    output:{
        path:path.join(__dirname,'./dist'),
        filename:'index.js'
    },
    mode:'development',
    module:{
        rules:[
            {
                test:/\.css$/,
                loader:['vue-style-loader','css-loader']
            },
            {
                test:/\.jpg$/,
                loader:['url-loader']
            },
            {
                test:/\.vue$/,
                loader:'vue-loader'
            }
        ]
    },
    plugins:[
        new VueLoaderPlugin(),
        new htmlPlugin({
            template:'./src/index.html'
        }),
        new webpack.HotModuleReplacementPlugin()
    ],
    resolve:{
        // alias:{
        //     'vue$':'vue/dist/vue.esm.js'
        // }
    },
    devServer:{
        port:9090,
        before(app){
            app.get('/api/list',(req,res) => {
                let list = require('./mock/list.json');
                res.end(JSON.stringify(list));
            })
        },
        hot:true
    }
}